#pragma once

#include <time.h>
#include <stdlib.h>


#ifndef GW2API_C_STRUCTS
#define GW2API_C_STRUCTS

//event-state-macros
#define EVT_ACTIVE 0
#define EVT_SUCCESS 1
#define EVT_FAIL 2
#define EVT_WARMUP 3
#define EVT_PREPARATION 4

//web-macros
#define APP_ID "GW2API"
#define API_SERVER "api.guildwars2.com"
#define DYNAMIC_EVENTS_API "/v1/events.json?world_id="
#define WORLD_MAPPING_API "/v1/world_names.json?"
#define MAP_MAPPING_API "/v1/map_names.json?"
#define EVENT_MAPPING_API "/v1/event_names.json?"
#define WVW_MATCHES "/v1/wvw/matches.json"
#define WVW_MATCH_DETAILS "/v1/wvw/match_details.json?match_id="
#define WVW_OBJECTIVE_NAMES "/v1/wvw/objective_names.json?"
#define ITEMS_API "/v1/items.json?"
#define ITEM_DETAILS "/v1/item_details.json?item_id="
#define RECIPES_API "/v1/recipes.json?"
#define RECIPE_DETAILS "/v1/recipe_details.json?recipe_id="
#define GUILD_API "/v1/guild_details.json?"
#define API_BUILD "/v1/build.json?"
#define COLORS_API "/v1/colors.json?"
#define GW2API_LANG_DE 0
#define GW2API_LANG_FR 1
#define GW2API_LANG_EN 2

#endif

enum json_type{List, Object, Integer, Float, String, Numeric, end, _undef=-1}; 
enum state{active, success, fail, warmup, preparation, undef=-1};

typedef struct json *jPtr;
typedef struct event *eventPtr;
typedef struct map *mapPtr;
typedef struct world *worldPtr;
typedef struct guild *guildPtr;

struct json{
	jPtr data;
	int i;
	double d;
	char *key, *string;
	enum json_type data_type, list_type;
};

struct event{
	char *event_name, *event_id;
	int map_id, world_id;
	enum state state;
};

struct map{
	char *map_name;
	int map_id;
	eventPtr events;
};

struct world{
	char *world_name;
	int world_id;
	mapPtr maps;
};


struct guild{
	char *id, *name, *tag;
};


void _free_evtptr(eventPtr);
void _free_mapptr(mapPtr);
void _free_worldptr(worldPtr);
void _free_guild_ptr(guildPtr);
void _free_jptr(jPtr);